<?php


namespace app\admin\model;


use think\facade\Log;
use think\Model;

class StaffReplyTime extends Model
{
    protected $autoWriteTimestamp = true;

    public static function add($staffNo, $userNo, $deviceType,$talk_no,$sendToNo)
    {
        $createDay = strtotime(date("Y-m-d", time()));
        $ti = StaffReplyTime::where("create_day", $createDay)
            ->where("user_no", $userNo)
            ->where("talk_no",$talk_no)
            ->where("device_type", $deviceType)
            ->find();
        if ($ti && $sendToNo == "user" && $ti["staff_no"] == "") {
            // 统计时间s
            $resTime = timeDiff(strtotime($ti["create_time"]), time());

            $arr = ["time_second_long" => $resTime["sec"], "update_time" => time(),"staff_no" => $staffNo];
            Log::info("StaffReplyTime".json_encode($arr));
            StaffReplyTime::where("id", $ti["id"])->data($arr)->update();
        } else if (!$ti && $sendToNo == "staff"){
            $timeArr = [
                "create_day" => $createDay,
                "user_no" => $userNo,
                "device_type" => $deviceType,
                "talk_no" =>$talk_no
            ];
            StaffReplyTime::create($timeArr);
        }
        return "";
    }
}